package com.haier.uos.weather.report.controller;

import com.haier.uos.weather.report.client.ApiClient;
import com.haier.uos.weather.report.service.IWeatherDataService;
import com.haier.uos.weather.report.vo.City;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/report")
public class WeatherReportController {
    private Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private IWeatherDataService weatherDataService;

    @Autowired
    private ApiClient apiClient;

    @GetMapping("/cityId/{cityId}")
    public ModelAndView getReportByCityId(@PathVariable String cityId, Model model) {
        List<City> cityList = apiClient.getCityList();
        model.addAttribute("title", "我的天气预报");
        model.addAttribute("cityList", cityList);
        model.addAttribute("cityId", cityId);
        model.addAttribute("report", weatherDataService.getDataByCityId(cityId));

        return new ModelAndView("weather/report", "reportModel", model);
    }
}
